package model

import (
	"auth/model/entity"
)

type ApiCreateRequest struct {
	Path string `json:"path" binding:"required"`

	Description string `json:"description" binding:"required"`

	ApiGroup string `json:"api_group" binding:"required"`

	Method string `json:"method" binding:"required"`
}

type ApiUpdateRequest struct {
	ID int64 `json:"id" binding:"required"`

	Path string `json:"path" binding:"required"`

	Description string `json:"description" binding:"required"`

	ApiGroup string `json:"api_group" binding:"required"`

	Method string `json:"method" binding:"required"`

	CreatedAt int64 `json:"created_at"`
}

type ApiListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	ID int64 `json:"id"`

	Path string `json:"path" `

	Description string `json:"description" `

	ApiGroup string `json:"api_group" `

	Method string `json:"method"`
}

type ApiListResponse struct {
	Total int        `json:"total"`
	Data  []*ApiInfo `json:"data"`
}

type GetAllApisResponse struct {
	Data []*ApiInfo `json:"data"`
}

type ApiInfo struct {
	ID int64 `json:"id"`

	Path string `json:"path"`

	Description string `json:"description"`

	ApiGroup string `json:"api_group"`

	Method string `json:"method"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

type ApiDeleteRequest struct {
	ID int64 `json:"id" binding:"required"`
}

func ApisEntityToDto(apis []*entity.Api) []*ApiInfo {
	out := make([]*ApiInfo, 0, len(apis))
	for _, c := range apis {
		out = append(out, ApiEntityToDto(c))
	}
	return out
}

func ApiEntityToDto(e *entity.Api) *ApiInfo {
	return &ApiInfo{

		ID: e.ID,

		Path: e.Path,

		Description: e.Description,

		ApiGroup: e.ApiGroup,

		Method: e.Method,

		CreatedAt: e.CreatedAt,

		UpdatedAt: e.UpdatedAt,
	}
}
